<%@page import="school.entity.Student"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%-- <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> --%>

<!DOCTYPE HTML>
<html>
  <head>
  	<%--${requestScope.contextPath}
  	 <%
  		//request.getAttribute("contextPath");
  		pageContext.getRequest()
  	 %> --%>
  	 <c:set var="q" value="${pageContext.request}"></c:set>
  	 
    <base href="${q.scheme}://${q.serverName}:${q.serverPort}${q.contextPath}/">
    
    <title>My JSP 'students.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="js/jquery-3.3.1.min.js"></script>
	
  </head>
  
  <body>
  <jsp:include page="/checkLogin.jsp"></jsp:include>
  <a href="addStudentServlet">新生注册</a>
  <span id="msg" style="color:red;">${msg}</span>
  
  <c:remove var="msg"/>
  <form action="studentSearchServlet">
  <input type="hidden" name="pageNo" id="pageNo" value="${pageNo}"/>
   <p>
   <input type="text" placeholder="请输入姓名查询" name="name" value="${name}">
   <input type="text" placeholder="请输入手机号查询" name="tele" value="${tele}">
   <input type="submit" value="search"/>
   </p>
  </form>
    <table align="center" width="80%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>学号</td><td>姓名</td><td>手机号</td><td>性别</td><td>操作</td>
    </tr>
   <%--  <%
    	
    	int p=(Integer)request.getAttribute("p");
    	 
    	int totalpage=(Integer)request.getAttribute("totalpage");
    	List<Student> list=(List<Student>)request.getAttribute("list");
    	for(Student s:list){
     %> --%>
     <c:forEach items="${list}" var="s">
     <tr>
     	<td>${s.stuno}</td>
     	<td>${s.sname}</td>
     	<td>${s.telephone}</td>
     	<td>${s.sex}</td>
     	<td><a onclick="return confirm('您是真的要删除[${s.sname}]吗？')" href="studentDelServlet?no=${s.stuno}">删除</a>
     		<a href="toUpdateStudent.jsp?no=${s.stuno}">修改</a>
     		
     		<a href="studentShowServlet?no=${s.stuno}">查看详细</a>
     	</td>
     </tr>
    </c:forEach>
     </table>
     <p id="pager">
     <%-- <a href="studentSearchServlet?pageNo=1&name=${name}&tele=${tele}">首页</a>   
    --%>
	<a href="studentSearchServlet?pageNo=1" pageNo="1">首页</a>   
     <c:if test="${p>1}">
  	<a href="studentSearchServlet?pageNo=${p-1}" pageNo="${p-1}">上一页</a>   
     &nbsp;
     </c:if>
     <c:if test="${p<totalpage}"> 
    <a href="studentSearchServlet?pageNo=${p+1}" pageNo="${p+1}">下一页</a> 
    </c:if>
     &nbsp;
     <input type="number" style="width:40px" name="pageNo" value="${p}"/><input type="button" value="GO" id="go"/>
     
   &nbsp;
    <a href="studentSearchServlet?pageNo=${totalpage}" pageNo="${totalpage}">最后一页</a>  
     共${totalpage}页</p>
     
     <script>
		$(function(){
			$("#msg").hide(4000);
			$("#pager a").click(function(){
				var pageNo=$(this).attr("pageNo");
				$("form #pageNo").val(pageNo);
				$("form").submit();
				return false;//让a失效
			});
			$("#go").click(function(){
				 var n=$(this).prev().val();
				 if(n<1)n=1;
				 if(n>${totalpage})
				 	n=${totalpage};
				 	
				//location='studentSearchServlet?pageNo='+n;
				$("form #pageNo").val(n);
				$("form").submit();
				
			});
		});
	</script>
	
  </body>
</html>
